package com.springboot2.validate.controller;

import com.springboot2.validate.vo.StudentVO;
import org.hibernate.validator.constraints.Length;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 数据校验Controller
 */
@Validated// 开启校验
@RestController
public class ValidateController {
    private static final Logger log = LoggerFactory.getLogger(ValidateController.class);

    @PostMapping("test")
    public String test(@Validated @RequestBody StudentVO studentVO) {
        log.info("数据校验通过...");
        return studentVO.toString();
    }

    @GetMapping("name")
    @ResponseBody
    public String validParam(@NotBlank String name) {
        return "nnnnnnn";
    }

    @PostMapping("param/{param}")
    @ResponseBody
    public String vaParam(@Length(min = 4) @PathVariable("param") String param) {
        return "ppppppp";
    }
}
